package org.cerberus.platform.internal.impl;

import java.util.Map;

import org.cerberus.platform.internal.IInternalPlatform;
import org.cerberus.platform.internal.IPlatformRegistry;
import org.cerberus.platform.internal.IProtocol;
import org.cerberus.platform.internal.IServer;

public class LocalServer implements IServer {

	private IPlatformRegistry registry;
	private IInternalPlatform platform;
	
	@Override
	public void start(IPlatformRegistry factory, Map<String, Object> parameters) {
		instance = this;
		this.registry = factory;
	}

	@Override
	public void stop() {
		disconnect();
	}

	public IProtocol connect(IProtocol response) {
		platform = registry.create();
		platform.setResponse(response);
		return new EventQueueProtocolWrapper(platform);
	}
	
	public void disconnect() {
		platform = null;
	}
	
	public static boolean isRunning() {
		return instance != null;
	}
	
	private static LocalServer instance;
	
	public static LocalServer getInstance() {
		return instance;
	}
	
	
}
